home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Include / Math.au3 < prev    next >
Encoding:
Text File  |  2007-09-08  |  6.5 KB  |  207 lines

  1. #include-once
  2.  
  3. ; ------------------------------------------------------------------------------
  4. ;
  5. ; AutoIt Version: 3.0
  6. ; Language:       English
  7. ; Description:    Functions that assist with mathematical calculations.
  8. ;
  9. ; ------------------------------------------------------------------------------
  10.  
  11.  
  12. ;=============================================================================
  13. ;
  14. ; Function Name:   _Degrees()
  15. ;
  16. ; Description:     Converts radians to degrees.
  17. ;
  18. ; Syntax:          _Degrees( $nRadians )
  19. ;
  20. ; Parameter(s);    $nRadians   = Radians to be converted into degrees.
  21. ;
  22. ; Requirement(s):  External:   = None.
  23. ;                  Internal:   = None.
  24. ;
  25. ; Return Value(s): On Success: = Returns the degrees converted from radians.
  26. ;                  On Failure: = Returns a blank string.
  27. ;                  @ERROR:     = 0 = No error.
  28. ;                                1 = $nRadians is not a number.
  29. ;
  30. ; Author(s):       Erifash <erifash at gmail dot com>
  31. ;
  32. ; Notes:           Multiplies instead of dividing.
  33. ;
  34. ; Example(s):
  35. ;   MsgBox(4096, "_Degree() Test", "_Degree( 3.1415 ) = " & _Radian( 3.1415 ))
  36. ;
  37. ;=============================================================================
  38. Func _Degree($nRadians)
  39.     If Not IsNumber($nRadians) Then
  40.         SetError(1)
  41.         Return ""
  42.     EndIf
  43.     Return $nRadians * 57.2957795130823
  44. EndFunc  ;==>_Degree()
  45.  
  46. ;===============================================================================
  47. ;
  48. ; Function Name:    _MathCheckDiv()
  49. ; Description:      Checks to see if numberA is divisable by numberB
  50. ; Parameter(s):     $i_NumA   - Dividend
  51. ;                   $i_NumB   - Divisor
  52. ; Requirement(s):   None.
  53. ; Return Value(s):  On Success - 1 if not evenly divisable
  54. ;                              - 2 if evenly divisable
  55. ;                   On Failure - -1 and @error = 1
  56. ; Author(s):        Wes Wolfe-Wolvereness <Weswolf at aol dot com>
  57. ;
  58. ;===============================================================================
  59. Func _MathCheckDiv($i_NumA, $i_NumB = 2)
  60.     If Number($i_NumA) = 0 Or Number($i_NumB) = 0 Or Int($i_NumA) <> $i_NumA Or Int($i_NumB) <> $i_NumB Then
  61.         Return -1
  62.         SetError(1)
  63.     ElseIf Int($i_NumA / $i_NumB) <> $i_NumA / $i_NumB Then
  64.         Return 1
  65.     Else
  66.         Return 2
  67.     EndIf
  68. EndFunc   ;==>_MathCheckDiv
  69.  
  70. ;===============================================================================
  71. ;
  72. ; Function Name:   _Max()
  73. ;
  74. ; Description:     Evaluates which of the two numbers is higher.
  75. ;
  76. ; Syntax:          _Max( $nNum1, $nNum2 )
  77. ;
  78. ; Parameter(s):    $nNum1      = First number
  79. ;                  $nNum2      = Second number
  80. ;
  81. ; Requirement(s):  External:   = None.
  82. ;                  Internal:   = None.
  83. ;
  84. ; Return Value(s): On Success: = Returns the higher of the two numbers
  85. ;                  On Failure: = Returns 0.
  86. ;                  @ERROR:     = 0 = No error.
  87. ;                                1 = $nNum1 isn't a number.
  88. ;                                2 = $nNum2 isn't a number.
  89. ;
  90. ; Author(s):       Jeremy Landes <jlandes at landeserve dot com>
  91. ;
  92. ; Note(s):         Works with floats as well as integers
  93. ;
  94. ; Example(s):
  95. ;   #Include <Math.au3>
  96. ;   MsgBox( 4096, "_Max() - Test", "_Max( 3.5, 10 )    = " & _Max( 3.5, 10 ) )
  97. ;   Exit
  98. ;
  99. ;===============================================================================
  100. Func _Max($nNum1, $nNum2)
  101.     ; Check to see if the parameters are indeed numbers of some sort.
  102.     If (Not IsNumber($nNum1)) Then
  103.         SetError(1)
  104.         Return (0)
  105.     EndIf
  106.     If (Not IsNumber($nNum2)) Then
  107.         SetError(2)
  108.         Return (0)
  109.     EndIf
  110.     
  111.     If $nNum1 > $nNum2 Then
  112.         Return $nNum1
  113.     Else
  114.         Return $nNum2
  115.     EndIf
  116. EndFunc   ;==>_Max
  117.  
  118. ;===============================================================================
  119. ;
  120. ; Function Name:   _Min()
  121. ;
  122. ; Description:     Evaluates which of the two numbers is lower.
  123. ;
  124. ; Syntax:          _Min( $nNum1, $nNum2 )
  125. ;
  126. ; Parameter(s):    $nNum1      = First number
  127. ;                  $nNum2      = Second number
  128. ;
  129. ; Requirement(s):  External:   = None.
  130. ;                  Internal:   = None.
  131. ;
  132. ; Return Value(s): On Success: = Returns the higher of the two numbers
  133. ;                  On Failure: = Returns 0.
  134. ;                  @ERROR:     = 0 = No error.
  135. ;                                1 = $nNum1 isn't a number.
  136. ;                                2 = $nNum2 isn't a number.
  137. ;
  138. ; Author(s):       Jeremy Landes <jlandes at landeserve dot com>
  139. ;
  140. ; Note(s):         Works with floats as well as integers
  141. ;
  142. ; Example(s):
  143. ;   #Include <Math.au3>
  144. ;   MsgBox( 4096, "_Min() - Test", "_Min( 3.5, 10 )    = " & _Min( 3.5, 10 ) )
  145. ;   Exit
  146. ;
  147. ;===============================================================================
  148. Func _Min($nNum1, $nNum2)
  149.     ; Check to see if the parameters are indeed numbers of some sort.
  150.     If (Not IsNumber($nNum1)) Then
  151.         SetError(1)
  152.         Return (0)
  153.     EndIf
  154.     If (Not IsNumber($nNum2)) Then
  155.         SetError(2)
  156.         Return (0)
  157.     EndIf
  158.     
  159.     If $nNum1 > $nNum2 Then
  160.         Return $nNum2
  161.     Else
  162.         Return $nNum1
  163.     EndIf
  164. EndFunc   ;==>_Min
  165.  
  166. ;=============================================================================
  167. ;
  168. ; Function Name:   _Radian()
  169. ;
  170. ; Description:     Converts degrees to radians.
  171. ;
  172. ; Syntax:          _Radian( $nDegrees )
  173. ;
  174. ; Parameter(s);    $nDegrees   = Degrees to be converted into radians.
  175. ;
  176. ; Requirement(s):  External:   = None.
  177. ;                  Internal:   = None.
  178. ;
  179. ; Return Value(s): On Success: = Returns the radians converted from degrees.
  180. ;                  On Failure: = Returns a blank string.
  181. ;                  @ERROR:     = 0 = No error.
  182. ;                                1 = $nDegrees is not a number.
  183. ;
  184. ; Author(s):       Erifash <erifash at gmail dot com>
  185. ;
  186. ; Notes:           In mathmatics and physics, the radian is a unit of
  187. ;                  angle measurement. One radian is approximately
  188. ;                  57.2957795130823 degrees. To figure out that number,
  189. ;                  use the formula ( 180 / pi ). Since pi is used in
  190. ;                  the formula the result is infinite in decimal places.
  191. ;                  The fact that AutoIt has a limited number of decimal
  192. ;                  places makes the result more innaccurate as you move
  193. ;                  down the decimal line. This is perfect for basic
  194. ;                  physics calculations though.
  195. ;
  196. ; Example(s):
  197. ;   MsgBox(4096, "_Radian() Test", "_Radian( 35 ) = " & _Radian( 35 ))
  198. ;
  199. ;=============================================================================
  200. Func _Radian($nDegrees)
  201.         If not Number($nDegrees) Then
  202.         SetError(1)
  203.         Return ""
  204.     EndIf
  205.     Return $nDegrees / 57.2957795130823
  206. EndFunc  ;==>_Radian()
  207.